package request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *  1.request实现服务器内部资源跳转
 *  2.共享数据：
 *             1.setAttribute
 *             2.getAttribute
 *             3.removeAttribute
 *  通过request进行转发后，可以将request的共享域扩大。
 *
 *  3.获取servletContext
 */

@WebServlet(value = "/request_demo5")
public class request_demo5 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("demo5 访问成功");
        request.setAttribute("msg","hello");//键值对形式的值
        //转发
        request.getRequestDispatcher("/request_demo6").forward(request,response);


        //3.获取servletContext
        System.out.println(request.getServletContext());

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
